package com.jd.sys.service.impl;

import com.jd.sys.domain.Role;
import com.jd.sys.mapper.MenuMapper;
import com.jd.sys.mapper.PermissionMapper;
import com.jd.sys.mapper.RoleMapper;
import com.jd.sys.service.IRoleService;
import com.jd.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author É°Ç³
 * @since 2023-03-09
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
    @Autowired
    RoleMapper roleMapper;
    @Autowired
    PermissionMapper permissionMapper;
    @Autowired
    MenuMapper menuMapper;
    public void add(Role role){
        roleMapper.add(role);
        roleMapper.removeRoleMenu(role.getId());
        roleMapper.removeRolePermission(role.getId());
        roleMapper.addRoleMenu(role.getId(),role.getMenus());
        roleMapper.addRolePermission(role.getId(),role.getPermissions());
    }
    public void update(Role role){
        roleMapper.update(role);
        menuMapper.deleteByRoleId(role.getId());
        menuMapper.addMid(role.getId(),role.getMenus());
        permissionMapper.deleteByRoleId(role.getId());
        permissionMapper.addMid(role.getId(),role.getPermissions());
    }

    public void delete(Long id){

    }

}
